<?php

// 广告位表

namespace app\console\model;
use think\Db;
use think\Model;
use think\Request;
use app\common\trilateral\Classify as ClassifyAlias;
use think\Session;
use think\Hook;

class ShopAssignor extends Model
{
    // 模型事件
    protected static function init()
    {
        self::event('before_insert', function ($data) {

            $shop_id = Db::name('shop_create')->where('manage_id',Session::get('manage_id'))->value('shop_id');
            $data->create_id = Session::get('manage_id');
//            $data->password = sha1($data->password);
//            halt(\session('shop_id'));
            if(empty(\session('shop_id')) && empty(Request::instance()->param('shop_id'))){
                fail('请选择门店');
            }else{
                $data->shop_id = \session('shop_id');
            }
            $a = Request::instance()->param('shop_id');
            if(isset($a)){
                $data->shop_id = Request::instance()->param('shop_id');
            }
           // $data->shop_id = Request::instance()->param('shop_id');

        });
        self::event('before_update', function ($data) {

            $shop_id = Db::name('shop_create')->where('manage_id',Session::get('manage_id'))->value('shop_id');
            $data->create_id = Session::get('manage_id');
            $data->shop_id = \session('shop_id');
        });
    }


}